package com.coszero.ui.recycler;

import android.content.Context;

import androidx.recyclerview.widget.RecyclerView;

import com.coszero.ui.R;
import com.coszero.utils.decoration.HorizontalDividerItemDecoration;
import com.coszero.utils.decoration.SpacingItemDecoration;
import com.coszero.utils.decoration.VerticalDividerItemDecoration;
import com.coszero.utils.utils.DensityUtil;
import com.coszero.utils.utils.ResourceUtils;

/**
 * Desc： RecyclerView 分割线
 * <p>
 * Author： xmqian
 * Email:xmqian93@163.com
 * Date: 2019/10/28 11:55
 */
public class RecyclerDiverUtils {
    /**
     * 默认分割线
     *
     * @param context
     * @return
     */
    public static RecyclerView.ItemDecoration hDiver(Context context) {
        return new HorizontalDividerItemDecoration.Builder(context).color(ResourceUtils.getColor(context, R.color.ui_list_line)).size(1).build();
    }

    public static RecyclerView.ItemDecoration hDiverMagin(Context context) {
        int i = DensityUtil.dip2px(context, 16);
        return new HorizontalDividerItemDecoration.Builder(context).color(ResourceUtils.getColor(context, R.color.ui_list_line)).size(1)
                .margin(i, i).build();
    }

    public static RecyclerView.ItemDecoration vDiver(Context context) {
        return new VerticalDividerItemDecoration.Builder(context).color(ResourceUtils.getColor(context, R.color.ui_list_line)).size(1).build();
    }

    public static RecyclerView.ItemDecoration vDiver(Context context, int color) {
        return new VerticalDividerItemDecoration.Builder(context).color(color).size((int)ResourceUtils.getDimension(context,R.dimen.ui_dp_8)).build();
    }

    public static RecyclerView.ItemDecoration vDiver(Context context, int color, int size) {
        return new VerticalDividerItemDecoration.Builder(context).color(color).size(DensityUtil.dip2px(context, size)).build();
    }

    /**
     * 横向分割线
     *
     * @param context
     * @param color
     * @param lineSize
     * @return
     */
    public static RecyclerView.ItemDecoration hDiver(Context context, int color, int lineSize) {
        return new HorizontalDividerItemDecoration.Builder(context).color(color).size(lineSize).build();
    }

    /**
     * 空白的分割线,已背景为准
     *
     * @param context
     * @param lineSize
     * @return
     */
    public static RecyclerView.ItemDecoration hSpaceDiver(Context context, int lineSize) {
        return new SpacingItemDecoration(1, DensityUtil.dip2px(context, lineSize), false);
    }

    // <editor-fold desc="空白背景分割线" defaultstate="collapsed">

    /**
     * 空白的分割线,已背景为准
     *
     * @param context context
     * @param lineSize 粗细 dp单位
     * @param spanCount 列数,根据表格列数决定
     * @return 构造好的间距
     */
    public static RecyclerView.ItemDecoration spaceDiver(Context context, int lineSize, int spanCount) {
        return new SpacingItemDecoration(spanCount, DensityUtil.dip2px(context, lineSize), false);
    }


    /**
     * 返回一列列表的分割线
     */
    public static RecyclerView.ItemDecoration spaceDiverH(Context context, int lineSize) {
        return spaceDiver(context, lineSize, 1);
    }

    //</editor-fold>

}
